# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running fastlane

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version '2.29.0'

default_platform :ios
skip_docs

platform :ios do
  before_all do
  end

  lane :install do
    bundle_install

    cocoapods(
      use_bundle_exec: true,
      try_repo_update_on_error: true
    )
  end

  lane :build do
    swiftlint(
      mode: :lint,
      config_file: '.swiftlint.yml',
      executable: 'Pods/SwiftLint/swiftlint',
      ignore_exit_status: true
    )

    # FlexLayout
    xcodebuild(
      workspace: 'FlexLayout.xcworkspace',
      scheme: 'FlexLayoutInner',
      configuration: 'Release',
      build: true,
      clean: true,
      destination: 'platform=iOS Simulator,name=iPhone 15,OS=17.2'
    )

    # FlexLayoutSample from FlexLayout.xcworkspace
    xcodebuild(
      workspace: 'FlexLayout.xcworkspace',
      scheme: 'FlexLayoutSample',
      configuration: 'Release',
      build: true,
      # clean: true,
      destination: 'platform=iOS Simulator,name=iPhone 15,OS=17.2'
    )

    # Example SPM (Swift Package Manager)
    xcodebuild(
      project: 'Example/SPM/FlexLayoutSample-SPM.xcodeproj',
      scheme: 'FlexLayoutSample-SPM',
      configuration: 'Release',
      build: true,
      clean: true,
      destination: 'platform=iOS Simulator,name=iPhone 15,OS=17.2'
    )
  end

  lane :tests do
    scan(scheme: 'FlexLayoutInner', workspace: 'FlexLayout.xcworkspace', device: 'iPhone 15')
  end

  lane :doc do
    jazzy
  end

  lane :travis do
    install
    tests
    build
    # pod_lib_lint(allow_warnings: true, verbose: false)
  end

  lane :deploy do
    ensure_git_branch
    version = version_bump_podspec(path: 'FlexLayout.podspec')
    git_commit(path: ['./FlexLayout.podspec'], message: "Bumped to version #{version}")
    push_to_git_remote(remote_branch: 'master', force: false, tags: true)
    changelog = changelog_from_git_commits
    github_release = set_github_release(
      repository_name: 'layoutBox/FlexLayout',
      api_token: ENV['GITHUB_TOKEN'],
      name: version,
      tag_name: version,
      description: changelog,
      commitish: 'master'
    )
    sh('git fetch --tags')
    pod_push(allow_warnings: true, verbose: true)
  end
end
